Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix describe on PostgreSQL views with rules #2736

Merged
merged 4 commits into from
Mar 14, 2024

Conversation

jwangnz
Copy link
Contributor

@jwangnz jwangnz commented Sep 6, 2023

This pull request fixes the issue that the Postgres describe function might not work on views with rules.

Steps to reproduce this issue

Create a table, a view, and a rule as follows:

create table t_test (id bigint);
create table t_test_d (id bigint);
create view v_test as select id from t_test;
create rule r1 as on insert to v_test do also (delete from t_test_d where id = new.id);
explain (verbose, format json) insert into v_test (id) values (1) returning id;

Run the explain:

explain (verbose, format json) insert into v_test (id) values (1) returning id;

The output is an array of multiple Explain struct:

                   QUERY PLAN                     
---------------------------------------------------
 [                                                +
   {                                              +
     "Plan": {                                    +
       "Node Type": "ModifyTable",                +
       "Operation": "Insert",                     +
       "Parallel Aware": false,                   +
       "Async Capable": false,                    +
       "Relation Name": "t_test",                 +
       "Schema": "public",                        +
       "Alias": "t_test",                         +
       "Startup Cost": 0.00,                      +
       "Total Cost": 0.01,                        +
       "Plan Rows": 1,                            +
       "Plan Width": 8,                           +
       "Output": ["t_test.id"],                   +
       "Plans": [                                 +
         {                                        +
           "Node Type": "Result",                 +
           "Parent Relationship": "Outer",        +
           "Parallel Aware": false,               +
           "Async Capable": false,                +
           "Startup Cost": 0.00,                  +
           "Total Cost": 0.01,                    +
           "Plan Rows": 1,                        +
           "Plan Width": 8,                       +
           "Output": ["'1'::bigint"]              +
         }                                        +
       ]                                          +
     }                                            +
   },                                             +
   {                                              +
     "Plan": {                                    +
       "Node Type": "ModifyTable",                +
       "Operation": "Delete",                     +
       "Parallel Aware": false,                   +
       "Async Capable": false,                    +
       "Relation Name": "t_test_d",               +
       "Schema": "public",                        +
       "Alias": "t_test_d",                       +
       "Startup Cost": 0.00,                      +
       "Total Cost": 38.25,                       +
       "Plan Rows": 0,                            +
       "Plan Width": 0,                           +
       "Plans": [                                 +
         {                                        +
           "Node Type": "Seq Scan",               +
           "Parent Relationship": "Outer",        +
           "Parallel Aware": false,               +
           "Async Capable": false,                +
           "Relation Name": "t_test_d",           +
           "Schema": "public",                    +
           "Alias": "t_test_d",                   +
           "Startup Cost": 0.00,                  +
           "Total Cost": 38.25,                   +
           "Plan Rows": 11,                       +
           "Plan Width": 6,                       +
           "Output": ["t_test_d.ctid"],           +
           "Filter": "(t_test_d.id = '1'::bigint)"+
         }                                        +
       ]                                          +
     }                                            +
   }                                              +
 ]
(1 row)

@abonander abonander merged commit 936744d into launchbadge:main Mar 14, 2024
62 checks passed
@jwangnz jwangnz deleted the fix-describe branch March 14, 2024 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants